import 'package:dio/dio.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MyInterceptors extends Interceptor {
  @override
  Future onError(DioError err) {
    print('------------------------错误响应数据---------------------------');
    print("type = ${err.type}");
    print("message = ${err.message}");
    print("stackTrace = ${err.error}");
    print('------------------------错误响应数据---------------------------');
    return super.onError(err);
  }

  @override
  Future onRequest(RequestOptions options) async {
    var pre = await SharedPreferences.getInstance();
    options.headers['token'] = pre.getString('token');
    print('------------------------请求数据---------------------------');
    print("url = ${options.uri.toString()}");
    print("headers = ${options.headers}");
    print("params = ${options.data}");
    print('------------------------请求数据---------------------------');
    return super.onRequest(options);
  }

  @override
  Future onResponse(Response response) {
    print('------------------------响应数据---------------------------');
    print("code = ${response.statusCode}");
    print("data = ${response.data}");
    print('------------------------响应数据---------------------------');
    return super.onResponse(response);
  }
}
